package org.ceteca.explica.core.partners;

import java.io.Serializable;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.ceteca.explica.core.common.BaseVO;



/**
 * @author Juan C. Díaz (juancarlosdiaz@ceteca.net) <br>
 *         Copyright (c) 2009 Fundación Centro Tecnolóxico da Carne
 * 
 * <br>
 * <br>
 *         This program is free software: you can redistribute it and/or modify
 *         it under the terms of the GNU General Public License as published by
 *         the Free Software Foundation, either version 3 of the License, or (at
 *         your option) any later version. <br/>
 *         This program is distributed in the hope that it will be useful, but
 *         WITHOUT ANY WARRANTY 
 *         <br>without even the implied warranty of
 *         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 *         General Public License for more details. <br/>
 *         You should have received a copy of the GNU General Public License
 *         along with this program. If not, see <http://www.gnu.org/licenses/>.
 * 
 */
public class VendorOT extends BaseVO implements Serializable {


	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private long idVendor;
	private String name;
	private String lastName;
	private String idNumber;
	private Float incomeTax;
	private Set<AddressOT> addressSet=new HashSet<AddressOT>();
	private Integer version=new Integer(0);
	
	
	
	
	
	public VendorOT() {
		super();

	}




	
	













	public String getName() {
		return name;
	}












	public void setName(String name) {
		this.name = name;
	}
























	public Float getIncomeTax() {
		return incomeTax;
	}












	public void setIncomeTax(Float incomeTax) {
		this.incomeTax = incomeTax;
	}























	public Set<AddressOT> getAddressSet() {
		return addressSet;
	}












	public void setAddressSet(Set<AddressOT> address) {
		this.addressSet = address;
	}












	public Integer getVersion() {
		return version;
	}










	
	@Override
	public boolean equals(Long id) {
		return id != null && this.idVendor == id.longValue();
	}

	@Override
	public String getEntityId() {

		return InterfacePartners.EXPLICA_ENTITY_VENDOR_ID;
	}

	@Override
	public long getInternalId() {

		return this.idVendor;
	}

	@Override
	public String getInternalValue() {
		
		return this.name+" "+this.lastName;
	}



















	public long getIdVendor() {
		return idVendor;
	}



















	public void setIdVendor(long idVendor) {
		this.idVendor = idVendor;
	}



















	public String getLastName() {
		return lastName;
	}



















	public void setLastName(String lastName) {
		this.lastName = lastName;
	}



















	public String getIdNumber() {
		return idNumber;
	}



















	public void setIdNumber(String idNumber) {
		this.idNumber = idNumber;
	}






	@Override
	public String toString() {
		StringBuffer result = new StringBuffer();
		
		try{
				result.append("\n%%%%%%%%%%%% BEGIN VENDOR DETAIL %%%%%%%%%%%%%%");
				result.append("\nID: ");
				result.append(this.idVendor);
				result.append("\nName: ");
				result.append(this.name);
				result.append("\n%%%%%%%%%%%% END VENDOR  DETAIL%%%%%%%%%%%%%%%%");
			}
			catch (Exception ex) {
				System.out.println("Error formatting Vendor!");
				ex.printStackTrace();
				return null;
			}
			
			return result.toString();
	}














	public void setVersion(Integer version) {
		this.version = version;
	}







	   @Override
	    public int hashCode() {
	        final HashCodeBuilder hcb = new HashCodeBuilder();
	        hcb.append(getIdNumber());
	        return hcb.toHashCode();
	    }

	    
	    
	    @Override
	    public boolean equals(Object obj) {
	        boolean isEquals = false;
	        try {
	            final VendorOT other = (VendorOT)obj;
	            final EqualsBuilder eqb = new EqualsBuilder();
	            eqb.append(getIdNumber(), other.getIdNumber());
	            isEquals = eqb.isEquals();

	        } catch (Exception e) {
	            isEquals = false;
	        }

	        return isEquals;
	    }


	    public void addAddress(Collection<AddressOT> toAdd){
	    	if (this.addressSet==null)
	    		addressSet=new HashSet<AddressOT>();
	    	addressSet.addAll(toAdd);
	    }

	    
	    public void clearAddress(){
	    	if (this.addressSet==null)
	    		addressSet=new HashSet<AddressOT>();
	    	addressSet.clear();
	    }





	
	
	
	
	
}
